package com.HQCourse.vod.vod.service.impl;

import com.example.HQCourse.model.vod.VideoVisitor;
import com.HQCourse.vod.vod.mapper.VideoVisitorMapper;
import com.HQCourse.vod.vod.service.VideoVisitorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.HQCourse.vo.vod.VideoVisitorCountVo;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 * 视频来访者记录表 服务实现类
 * </p>
 *
 * @author zww
 * @since 2023-06-30
 */
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor> implements VideoVisitorService {


    @Override
    public Map<String, Object> findCount(Long courseId, String startData, String endTime) {
        System.out.println("==============");

        //创建map集合
        List<VideoVisitorCountVo> videoVisitorCountVos=baseMapper.findCount(courseId,startData,endTime);
        System.out.println("===========================");
        System.out.println(videoVisitorCountVos);
        //创建两个list集合 分别存储x轴和y轴
        Map<String, Object> objectObjectHashMap = new HashMap<>();
        List<String> list=videoVisitorCountVos.stream().map(new Function<VideoVisitorCountVo, String>() {
            @Override
            public String apply(VideoVisitorCountVo videoVisitorCountVo) {
                return videoVisitorCountVo.getJoinTime();
            }
        }).collect(Collectors.toList());
        List<Integer> list1 = videoVisitorCountVos.stream().map(new Function<VideoVisitorCountVo, Integer>() {
            @Override
            public Integer apply(VideoVisitorCountVo videoVisitorCountVo) {
                return videoVisitorCountVo.getUserCount();
            }
        }).collect(Collectors.toList());
        objectObjectHashMap.put("xData",list);
        objectObjectHashMap.put("yData",list1);
        return objectObjectHashMap;
    }
}
